//
//  CHSCAnimationListController.m
//  ZXAnimationUtil_Example
//
//  Created by 朱新明 on 2023/9/10.
//  Copyright © 2023 simon. All rights reserved.
//  首页

#import "CHSCAnimationListController.h"
#import <ZXCategoriesUtil/CAICategories.h>
#import <Masonry/Masonry.h>
#import "CHSLayerContentController.h"
#import "CHSLayerAppearanceController.h"
#import "CHSOffScreenDrawController.h"
#import "CHSInterviewQListController.h"
#import "CHSTwoAnimationController.h"

@interface CHSCAnimationListController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataMArray;

@end

@implementation CHSCAnimationListController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setUI];
    [self setData];
}

- (void)setUI
{
    self.view.backgroundColor = [UIColor zx_colorWithHexString:@"#FDFEFF"];
    
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view.mas_left).with.offset(15);
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.top.equalTo(self.view.mas_top).with.offset(0);
        make.bottom.equalTo(self.view.mas_bottom);
    }];

}


#pragma mark - Data

- (void)setData
{
    NSArray *arr = @[
        @{@"1":@"设置图层内容"},
        @{@"2":@"设置图层外观：圆角、边框等"},
        @{@"3":@"面试题：离屏渲染的理解"},
        @{@"4":@"其它面试题列表"},
        @{@"5":@"图层对象定义自己的几何结构"},
        @{@"6":@"隐式动画（implicit animation）和显示动画（explicitly animate）例子"},
    ];
    self.dataMArray = [NSMutableArray arrayWithArray:arr];
    //    self.dataMArray = [NSMutableArray array];
    [self requestData];
}

- (void)requestData
{
    
}


#pragma mark -

- (UITableView *)tableView
{
    if (!_tableView)
    {
        UITableView *view = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        view.backgroundColor = self.view.backgroundColor;
        view.delegate = self;
        view.dataSource = self;
        view.showsVerticalScrollIndicator = NO;
        [view registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
        view.estimatedRowHeight = 87;
        view.rowHeight = UITableViewAutomaticDimension;
        if (@available(iOS 15.0, *)) {
            view.sectionHeaderTopPadding = 0;
        } else {
            // Fallback on earlier versions
        }
        _tableView = view;
    }
    return _tableView;
}



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataMArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    //    CHSMyRedpacketTableCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    //    [cell setData:nil];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    NSDictionary *dic = [self.dataMArray objectAtIndex:indexPath.row];
    NSString *value = [dic.allValues firstObject];
    cell.textLabel.text = value;
    cell.textLabel.numberOfLines = 0;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return 0.01;
    }
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return nil;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return [UIView new];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSDictionary *dic = [self.dataMArray objectAtIndex:indexPath.row];
    NSString *key = [dic.allKeys firstObject];
    if ([key isEqualToString:@"1"]) {
        CHSLayerContentController *vc = [CHSLayerContentController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
    else if ([key isEqualToString:@"2"]) {
        CHSLayerAppearanceController *vc = [CHSLayerAppearanceController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
    else if ([key isEqualToString:@"3"]) {
        CHSOffScreenDrawController *vc = [CHSOffScreenDrawController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
    else if ([key isEqualToString:@"4"]) {
        CHSInterviewQListController *vc = [CHSInterviewQListController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
    else if ([key isEqualToString:@"6"]) {
        CHSTwoAnimationController *vc = [CHSTwoAnimationController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
